﻿using Direct.IDAL;
using Direct.IDAL.User.Jurisdiction;
using DirectSell.Common.CodeHelp;
using DirectSell.Common.Filter;
using DirectSell.IBLL;
using DirectSell.Model.User;
using Microsoft.Practices.Unity;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
namespace DirectSell.WebLayer.Areas.User.Controllers.Jurisdiction
{
    /// <summary>
    /// 会员注册
    /// </summary>
    public class JurisdictionController : Controller
    {
        #region 依赖注入--郭文昊--2018年8月19日03:46:57
        /// <summary>
        /// 用户注册
        /// </summary>
        [Dependency("UserReigster")]
        public IOperation register { get; set; }

        [Dependency]
        public IRegisterRepository _dalRegist { get; set; }
        #endregion

        #region 会员注册页面--郭文昊--2018年8月20日20:46:48
        // GET: User/Jurisdiction
        [LoginFilter(IsCheck =true)]
        public ActionResult Index()
        {
            var Level = _dalRegist.QueryMemberLevel();
            //var selectItemList = new List<SelectListItem>() {
            //    new SelectListItem(){Value="0",Text="请选择会员级别",Selected=true}
            //};
            var selectItemList = new List<SelectListItem>();
             
            var selectList = new SelectList(Level, "LevelID", "SelectFileds", "LevelID");
            selectItemList.AddRange(selectList);
            ViewBag.database = selectItemList;

            #region 填充数据
            ViewBag.UserCode = ValidateCode.GetRandString(5);
            ViewBag.UserName = ValidateCode.GenerateCheckCode();
            ViewBag.IdNumber = ValidateCode.GetRandNumber(17);
            ViewBag.Phone = ValidateCode.GetRandNumber(11);
            ViewBag.BankName = ValidateCode.GenerateCheckCode();
            ViewBag.BankCode = ValidateCode.GetRandNumber(10);
            ViewBag.CardHolder = ValidateCode.GenerateCheckCode();
            #endregion

            return View(Level);
        }
        #endregion

        #region 会员注册--郭文昊--2018年8月19日03:43:55
        /// <summary>
        /// 会员注册
        /// </summary>
        /// <param name="model">会员注册信息</param>
        /// <returns></returns>
        public async Task<UserRespCode> Register(UserInforMationDetails model)
        {
            model.UserLevel = Convert.ToInt16(Request.Form["database-dropdownlist"]);
            if (model.UserLevel == 0)
            {
                return UserRespCode.请选择会员级别;
            }
            var result =  await register.DoOperationAsync<UserInforMationDetails>(model);
            return result;
        }
        #endregion
    }
}